package org.example.service.impl;

import io.seata.spring.annotation.GlobalTransactional;
import org.example.aip.OrderService;
import org.example.aip.StorageService;
import org.example.service.BusinessService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BusinessServiceImpl implements BusinessService {



    private static Logger logger = LoggerFactory.getLogger(BusinessServiceImpl.class) ;

    @Autowired
    private StorageService storageService;

    @Autowired
    private OrderService orderService;

    @Override
    @GlobalTransactional
    public void purchase(String userId, String commodityCode, int orderCount) {
        logger.info("准备下单，用户：{}，商品：{}，数量： {}",userId,commodityCode,orderCount);
        storageService.deduct(commodityCode, orderCount);
        orderService.create(userId, commodityCode, orderCount) ;
        logger.info("下单完成");
    }
}
